Skip to content

Conversation

ayushb
Copy link
Member

@ayushb ayushb commented Sep 14, 2026

Solves #12. Stacked on #24, so review that one first. The chain is this branch -> fix/issue-6-build-errors -> issue-6 -> main.

Adds the filter view the issue asks for: the user changes the rules, and the PokemonList reloads from them. The rules go through useFilters, so they are already kept in session storage and survive a reload.

The component

Filter is presentational in the same shape as Favorite, taking filters, onChange and onReset. It sits in the header row next to the navigation.

It is collapsed behind a details / summary disclosure, which keeps the header row from being crowded by eighteen type checkboxes and gives keyboard and screen reader support without a third party component. The summary shows how many rules are active so you can see at a glance that something is filtered while it is shut. Controls are grouped in fieldset / legend with a label on every input.

Three rules are exposed:

  • Sort by lowest or highest id, as radio buttons
  • Type, any number of the eighteen types, as checkboxes
  • Only show favorites, as a checkbox

The stat range rules the model already supports (hp, attack, height and so on) are deliberately left out of the UI for now. They keep working through the model and can get controls later.

Wiring the rules up

sort and onlyFavorites were in the model but were not read anywhere, so picking them would have done nothing. Both are applied now:

  • Sorting orders the list by id in the chosen direction.
  • With favorites only, the list shows the favorites instead of the neighbours of the current pokemon, with the other rules still applied on top.

The favorites view reuses the pokemon useFavorites has already fetched rather than asking the api again, so switching it on costs no extra calls. The list query is disabled while it is on.

Also removes FilterSettings, which nothing referenced after the model moved to FilterRules.

Tests

Fourteen new tests, none of them touching the network.

  • Filter.test.tsx, nine tests on props, on the toggle state, and on user interaction, plus a snapshot
  • PokemonList.test.tsx, five tests, restoring the file that was removed in chore: glue components together #23. Covers the fetched order, the reversed order, the favorites view, the other rules applying to favorites, and the empty state. It also asserts that the favorites view calls neither GetNextFiltered nor GetPrevFiltered.

setupTests.ts now imports @testing-library/jest-dom/vitest instead of the plain entry point. The matchers were already loaded at runtime, but their types were not, so toBeChecked and toBeInTheDocument failed under tsc.

Checks

tsc -b, eslint ., prettier --check and vite build are all clean. vitest run is 48 passed across 9 files, up from 34 across 7.

* Build Filter as a presentational component with filters, onChange and onReset props
* Collapse the panel behind a details summary that counts the active rules
* Let the user pick sort order, any number of types and favorites only
* Apply the sort order and the favorites rule when building the list
* Reuse the favorites already fetched instead of asking the api again
* Drop the unused FilterSettings type left over from the filter model
* Register the jest-dom matcher types so tests can assert on checked state
* Add tests for the component and for the list it filters

References #12
@ayushb
Copy link
Member Author

ayushb commented Sep 15, 2026

Same as #24, this one's part of #26 now. Review there instead.

@ayushb ayushb closed this Sep 15, 2026
@thomhet thomhet deleted the feat/issue-12-filter-component branch September 18, 2026 22:58
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant